<% content_for :page_title do %>
  <% if controller_name == 'orders' %>
    <%= page_header_back_button spree.admin_orders_path, @order %>
  <% else %>
    <%= page_header_back_button spree.edit_admin_order_path(@order) %>
  <% end %>
  <%= @order.number %>
  <%= order_payment_state(@order, class: 'ml-3') %>
  <%= order_shipment_state(@order, class: 'ml-3') %>
  <%= local_time(@order.completed_at, class: 'badge badge-light with-tip ml-3') if @order.completed? %>
<% end %>

<% content_for(:page_actions_dropdown) do %>
  <% if @order.completed? && spree.respond_to?(:order_path) %>
    <%= link_to_with_icon 'eye',
                          Spree.t(:preview),
                          spree.order_path(@order, host: current_store.url, token: @order.token),
                          class: 'text-left dropdown-item',
                          target: '_blank' %>
  <% end %>
  <% if @order.completed? && can?(:resend, @order) %>
    <%= link_to_with_icon 'send',
                          Spree.t(:resend),
                          resend_admin_order_path(@order),
                          data: { turbo_method: :post, turbo_confirm: Spree.t(:are_you_sure) },
                          class: 'btn btn text-left rounded-0 dropdown-item' %>
  <% end %>

  <% if can?(:cancel, @order) %>
    <div class="dropdown-divider"></div>
    <%= link_to spree.cancel_admin_order_path(@order),
                class: 'text-left btn-danger dropdown-item',
                data: { turbo_method: :put, turbo_confirm: Spree.t(:are_you_sure) } do %>
      <%= icon 'cancel' %>
      <%= Spree.t(:cancel_order) %>
    <% end %>
    <div class="dropdown-divider"></div>
  <% end %>
<% end %>
